{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "k-xIA7Qjuiwu"
      },
      "source": [
        "# 🐫 📊 CAMEL-AI PPTXToolkit Cookbook\n",
        "\n",
        "This notebook shows you how to **automatically generate** and **assemble** professional PowerPoint decks using CAMEL-AI’s PPTXToolkit. You’ll learn how to:\n",
        "\n",
        "- Prompt an LLM to produce **fully structured JSON** for every slide  \n",
        "- Turn that JSON into a polished `.pptx` with **titles**, **bullets**, **step diagrams**, **tables**, and **images**  \n",
        "- Leverage **Markdown** styling (`**bold**`, `*italic*`) and **Pexels** image search via `img_keywords`  \n",
        "- Plug in your **own .pptx templates** (modern, boardroom, minimalist, etc.)  \n",
        "- Enjoy **auto-layout** selection for text, diagrams, and tables  \n",
        "\n",
        "<hr />\n",
        "\n",
        "## 🚥 Pipeline Overview\n",
        "\n",
        "1. **Single Agent: Content → JSON**  \n",
        "   - You send one prompt to the LLM  \n",
        "   - It returns a JSON list with:\n",
        "     - A **title slide** (`title`, `subtitle`)  \n",
        "     - At least one **step-by-step** slide (all bullets start with `>>`)  \n",
        "     - At least one **table** slide (`table`: `{headers, rows}`)  \n",
        "     - Two or more slides with meaningful `img_keywords`  \n",
        "     - All **bullet slides** using Markdown formatting  \n",
        "\n",
        "2. **PPTXToolkit: JSON → `.pptx`**  \n",
        "   - Pass that JSON into `PPTXToolkit.create_presentation(...)`  \n",
        "   - Renders slides with your chosen template, images via `img_keywords`, chevrons/pentagons, and tables  \n",
        "   - Outputs a ready-to-share PowerPoint file  \n",
        "\n",
        "---\n",
        "\n",
        "Ready to build your next deck? Let’s get started! 🎉  \n",
        "\n",
        "You can also check this cookbook in colab [here](https://colab.research.google.com/drive/1W_dsoq1jrO8A_TzwUxzAr4wFSWeXLmn7?usp=sharing)\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": true,
        "id": "kR2UeIHFUBMf"
      },
      "outputs": [],
      "source": [
        "%pip install \"camel-ai[all]==0.2.66\""
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "FIz0b9O_wqkW"
      },
      "source": [
        "## ⚙️ Configuration\n",
        "Set your API keys securely:"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "HGpgR_XitX_B"
      },
      "outputs": [],
      "source": [
        "from getpass import getpass\n",
        "import os\n",
        "\n",
        "# Prompt the user securely (input is hidden)\n",
        "os.environ[\"OPENAI_API_KEY\"] = getpass(\"🔑 Enter your OpenAI API key: \")\n",
        "os.environ[\"PEXELS_API_KEY\"] = getpass(\"🔑 Enter your Pexels API key (leave blank if not using images): \")\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "HtP_ej5CyUNT"
      },
      "source": [
        "## ✏️ Agent #1: Generate Structured JSON\n",
        "One single LLM call to produce exactly the JSON your toolkit expects."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 118,
      "metadata": {
        "id": "ClqLd4HKypTI"
      },
      "outputs": [],
      "source": [
        "import os, json\n",
        "from camel.agents import ChatAgent\n",
        "from camel.models import ModelFactory\n",
        "from camel.types import ModelPlatformType, ModelType\n",
        "\n",
        "def generate_slides_json(topic: str, slide_count: int) -> list:\n",
        "    # Build our strict prompt\n",
        "    prompt = f\"\"\"\n",
        "You are a world-class PowerPoint generator for CAMEL-AI's PPTXToolkit.\n",
        "\n",
        "Create a presentation about \"{topic}\" with exactly {slide_count + 1} slides (1 title + {slide_count} content).\n",
        "MANDATORY:\n",
        "1. First slide: title & subtitle.\n",
        "2. ≥1 step-by-step slide (all bullets start with \">>\").\n",
        "3. ≥1 table slide (with headers & rows).\n",
        "4. ≥2 slides with non-empty img_keywords (search terms only).\n",
        "5. Bullet slides use Markdown (**bold**, *italic*) in bullet_points.\n",
        "6. Output MUST BE raw JSON (list of dicts), no markdown fences or commentary.\n",
        "\n",
        "Example:\n",
        "[\n",
        "  {{\"title\":\"...\",\"subtitle\":\"...\"}},\n",
        "  {{\"heading\":\"...\",\"bullet_points\":[\"...\",\"...\"],\"img_keywords\":\"...\"}},\n",
        "  {{\"heading\":\"...\",\"bullet_points\":[\">> Step 1...\"],\"img_keywords\":\"...\"}},\n",
        "  {{\"heading\":\"...\",\"table\":{{\"headers\":[\"A\",\"B\"],\"rows\":[[\"1\",\"2\"],[\"3\",\"4\"]]}},\"img_keywords\":\"...\"}}\n",
        "]\n",
        "\"\"\"\n",
        "    agent = ChatAgent(\n",
        "        system_message=\"You strictly output valid JSON for PowerPoint slides.\",\n",
        "        message_window_size=5,\n",
        "        model=ModelFactory.create(\n",
        "            model_platform=ModelPlatformType.OPENAI,\n",
        "            model_type=ModelType.GPT_4_1,\n",
        "            model_config_dict={\"temperature\": 0.0},\n",
        "        )\n",
        "    )\n",
        "    resp = agent.step(prompt)\n",
        "    slides = json.loads(resp.msgs[0].content)\n",
        "    return slides\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "z35CIla3zBF4"
      },
      "source": [
        "## 📦 Build & Save PPTX\n",
        "\n",
        "Local code uses PPTXToolkit to turn that JSON into a .pptx file:"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "QkURpvVUT9Rk"
      },
      "outputs": [],
      "source": [
        "from camel.toolkits.pptx_toolkit import PPTXToolkit\n",
        "\n",
        "def build_pptx(slides_json: list, out_name: str = \"presentation.pptx\") -> str:\n",
        "    kit = PPTXToolkit(output_dir=\".\")\n",
        "    kit.create_presentation(json.dumps(slides_json), out_name)\n",
        "    return out_name"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "-WXOG-Hr1ibN"
      },
      "source": [
        "## 🔗 Run the Pipeline"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "WnOXRacP1fbB"
      },
      "outputs": [],
      "source": [
        "if __name__ == \"__main__\":\n",
        "    topic = input(\"🎯 Topic: \")\n",
        "    n     = int(input(\"📄 # of content slides: \"))\n",
        "    slides = generate_slides_json(topic, n)\n",
        "    filename = f\"{topic.replace(' ','_')}.pptx\"\n",
        "    path = build_pptx(slides, out_name=filename)\n",
        "    print(f\"✅ Deck saved to: {path}\")\n"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
